package com.company.cloud.common.utils;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.springframework.util.StringUtils;

import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.common.constant.BaseCodeEnum;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;


public class CheckUtils {

	/**NULL:true*/
	public static boolean isEmpty(String str) {
		return StringUtils.isEmpty(str);
	}
	
	/**NULL:true*/
	public static boolean isEmpty(Integer i) {
		if(i==null ) {
			return true;
		}else {
			return false;
		}
	} 
	
	
	public static boolean hasBaseCodeEnum(BaseCodeEnum e) {
		if(e!=null) {
			return true;
		}else {
			return false;
		}
	}
	
	/**NULL:false*/
	public static boolean hasText(String str) {
		return StringUtils.hasText(str);
	}
	
	public static boolean hasObj(Object obj) {
		if(obj!=null) {
			return true;
		}else {
			return false;
		}
	}
	
	/**NULL:false*/
	public static boolean hasInt(Integer i) {
		if(i!=null && i>0) {
			return true;
		}else {
			return false;
		}
	}
	
	public static boolean hasBigDecimal(BigDecimal b) {
		if(b==null) {
			return false;
		}
		return b.doubleValue()>0?true:false;
	}
	
	/**NULL:false*/
	public static boolean hasList(List<?> v) {
		if(v!=null && v.size()>0) {
			return true;
		}else {
			return false;
		}
	}
	
	public static boolean hasSet(Set<?> v) {
		if(v!=null && v.size()>0) {
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 判断obj是否List
	 * */
	public static boolean isList(Object obj) {
		if (obj instanceof List) {
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 判断obj是否Set
	 * */
	public static boolean isSet(Object obj) {
		if (obj instanceof Set) {
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 判断obj是否Set
	 * */
	public static boolean isCollection(Object obj) {
		if (obj instanceof Collection) {
			return true;
		}else {
			return false;
		}
	}
	
	
	@SuppressWarnings("rawtypes")
	public static boolean hasClientResult(BaseClientResult obj) {
		if(obj==null) {
			return false;
		}
		if(BaseReturnEnum.SUCCESS.getCode().equals(obj.getCode())) {
			return true;
		}else {
			return false;
		}
	}
	
	
	@SuppressWarnings("rawtypes")
	public static void checkClientResult(BaseClientResult obj) throws BusinessException{
		if(obj==null) {
			throw new BusinessException(BaseReturnEnum.DATA_NOT_EXISTS);
		}
		if(!BaseReturnEnum.SUCCESS.getCode().equals(obj.getCode())) {
			throw new BusinessException(obj.getCode(),obj.getMsg());
		}
	}
	
	
	
	
	
	
//	public static String getVal(String val,String defVal) {
//		if(StringUtils.isEmpty(val)) {
//			return defVal;
//		}else {
//			return val;
//		}
//	}

}
